package ex04.pyrmont;

import com.sky.JULLog.MyLogger;
import org.apache.catalina.Container;
import org.apache.catalina.Logger;

import java.beans.PropertyChangeListener;
import java.util.logging.Level;

/**
 * 日志适配器,  默认 jul 实现日志..
 */
public class MyLoggerV4Adapter implements Logger {


    private static java.util.logging.Logger log  = null;
    private int verbosity = 4;


    private static java.util.logging.Logger getLog() {
        return log;
    }

    public MyLoggerV4Adapter(  ) {
        log= MyLogger.getLogger(this.getClass());
    }

    public MyLoggerV4Adapter(Class clazz  ) {
        log  = MyLogger.getLogger(clazz);

    }

    @Override
    public Container getContainer() {
        return null;
    }

    @Override
    public void setContainer(Container container) {

    }

    @Override
    public String getInfo() {
        return "JUL 适配器";
    }

    @Override
    public int getVerbosity() {
        return verbosity;
    }

    @Override
    public void setVerbosity(int verbosity) {
        this.verbosity = verbosity ;
    }

    @Override
    public void addPropertyChangeListener(PropertyChangeListener listener) {

    }

    @Override
    public void log(String message) {
        log.info(message);
    }

    @Override
    public void log(Exception exception, String msg) {
        log.log(Level.SEVERE, msg, exception);
    }

    @Override
    public void log(String message, Throwable throwable) {
        if (throwable == null){
            log.log(Level.WARNING, message);
        }
        log.log(Level.SEVERE, message, throwable);
    }

    @Override
    public void log(String message, int verbosity) {

        if (verbosity == 4) {
            log.log(Level.CONFIG, message);
        } else if (verbosity == 3) {
            log(message);

        } else if (verbosity == 2) {

            log.warning(message);
        } else if (verbosity == 1) {

            log.severe(message);
        } else {

            System.out.println(message);
        }


    }

    @Override
    public void log(String message, Throwable throwable, int verbosity) {
        log.log(Level.SEVERE , message , throwable) ;
    }

    @Override
    public void removePropertyChangeListener(PropertyChangeListener listener) {

    }




}
